//
//  ViewController.m
//  Homework_12(2)
//
//  Created by 徐昊 on 16/7/29.
//  Copyright © 2016年 徐昊. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UITextField *textfield;
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    // 修改textField的placeholder的颜色
    [self.textfield setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
    [self.passwordTextField setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
    // 修改textField的placeholder的字体
//    [self.textfield setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];
}
- (void)textFieldDidBeginEditing:(UITextField *)textField {
    if (textField.tag == 1) {
        UIImageView *i = [self.view viewWithTag:10];
        [i setImage:[UIImage imageNamed:@"icon_username_select"]];
    }
    if (textField.tag == 2) {
        UIImageView *i = [self.view viewWithTag:20];
        [i setImage:[UIImage imageNamed:@"icon_password_select"]];
    }
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
    if (textField.tag == 1) {
        UIImageView *i = [self.view viewWithTag:10];
        [i setImage:[UIImage imageNamed:@"icon_username"]];
    }
    if (textField.tag == 2) {
        UIImageView *i = [self.view viewWithTag:20];
        [i setImage:[UIImage imageNamed:@"icon_password"]];
    }
}

/** 点击回车收回键盘 */
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField endEditing:YES];
    return YES;
}

/** 点击屏幕收回键盘 */
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
